#define DEBUG
#include <cstdio>
#define INF 0xfffffff
#define MAXN 100000

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class SegmentTree {
public:
  unsigned int minv[4*MAXN+1], sumv[4*MAXN+1];

  void merge(int o) {
    minv[o] = min(minv[o*2], minv[o*2+1]);
    sumv[o] = sumv[o*2]+sumv[o*2+1];
  }

  void build(int o, int l, int r, int *a) {
    if (l==r) {
      sumv[o] = minv[o] = a[l];
    } else {
      int mid=(l+r)/2;
      build(o*2, l, mid, a);
      build(o*2+1, mid+1, r, a);
      merge(o);
    }
  }

  void get(int o, int l, int r, int tl, int tr, unsigned int &tmin, unsigned int &tsum) {
    if (l==tl && r==tr) {
      tmin = min(tmin, minv[o]);
      tsum += sumv[o];
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	get(o*2, l, mid, max(l, tl), min(mid, tr), tmin, tsum);
      }
      if (tl<=r && tr>mid) {
	get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr), tmin, tsum);
      }
    }
  }
};

void qsort(int *d, int *v, int l, int r) {
  int i=l, j=r, mid=d[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; d[j]>mid; j--);
    for (; d[i]<mid; i++);
    if (i<=j) {
      temp=d[i], d[i]=d[j], d[j]=temp;
      temp=v[i], v[i]=v[j], v[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    qsort(d, v, i, r);
  }
  if (j>l) {
    qsort(d, v, l, j);
  }
}

unsigned int solve(int *v, int l, int r, int k, int min, unsigned int sum) {
  static bool book[MAXN+1];
  if (k<=0) {
    return sum;
  } else {
    unsigned int ans=0;
    for (int i=l; i<=r; i++) {
      if (!book[i] && v[i]!=min) {
	book[i] = true;
	ans += solve(v, l, r, k-1, min, v[i]*sum);
	book[i] = false;
      }
    }
    return ans;
  }
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static int d[MAXN+1], v[MAXN+1];
  static SegmentTree sgt;
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i=1; i<=n; i++) {
    scanf("%d", d+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", v+i);
  }
  qsort(d, v, 1, n);

  sgt.build(1, 1, n, v);

  for (int i=1; i<=q; i++) {
    int l, r, k;
    scanf("%d %d %d", &l, &r, &k);
    int ansl=1, ansr=n;
    for (int x=1, y=n, mid; x<=y; ) {
      mid=(x+y)/2;
      if (d[mid]>=l) {
	ansl = mid;
	y = mid-1;
      } else {
	x = mid+1;
      }
    }
    for (int x=1, y=n, mid; x<=y; ) {
      mid=(x+y)/2;
      if (d[mid]<=r) {
	ansr = mid;
	x = mid+1;
      } else {
	y = mid-1;
      }
    }
    unsigned int minv=INF, sumv=0;
    sgt.get(1, 1, n, ansl, ansr, minv, sumv);
    if (k==1) {
      printf("%u\n", sumv-minv);
    } else {
      printf("%u\n", solve(v, ansl, ansr, k, minv, 1));
    }
  }

  fcloseall();
  return 0;
}
